package com.zhuiyi.springbootmybatis.service.impl;

import com.zhuiyi.springbootmybatis.entity.User;
import com.zhuiyi.springbootmybatis.mapper.UserMapper;
import com.zhuiyi.springbootmybatis.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public List<User> getUsers(){
       return userMapper.getUsers();
    }
    @Override
    public void addUser(User user) {
        userMapper.addUser(user);
    }

    @Override
    public void deleteUser(int id) {
        userMapper.delereUserById(id);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    @Override
    public User getUser(int id) {
        User user = userMapper.getUserById(id);
        return user;
    }

    @Override
    public String login(User user) {
        String userName = user.getUsername();
        String password = user.getPassword();
        User user1 = userMapper.login(userName, password);
        if (user1 != null) {
            return "success";
        } else {
            return "fail";
        }
    }


}
